// app.js
const api = require("./config/api");

App({
  api:api,
  onLaunch() {
    // 展示本地存储能力
    // const logs = wx.getStorageSync('logs') || []
    // logs.unshift(Date.now())
    // wx.setStorageSync('logs', logs)

    var that = this;
    wx.login({
      success: res => {
        wx.request({
          url: that.globalData.urlHome + '/login/getUserInfo',
          data:{
            code:res.code,
          },
          method:'GET',
          success(res){
            console.log(res);
            var token = res.header["x-auth-token"];
            var openid = res.header.openid;
            that.globalData.token = token;
            that.globalData.openid = openid;
            // that.getUserTask();
          }
        })
      }
    })
  },
  getUserTask() {
    var that = this;
    wx.request({
      url: that.globalData.urlHome + '/task/getTodayTask',
      header: {
        "accept": "*/*",
        "content-type": "application/json",
        "Authorization": that.globalData.token
      },
      data: {
        "openid": that.globalData.openid,
      },
      method: 'POST',
      success(r) {
        console.log(r.data);
      },
      fail(e) {

      }
    })
  },
  globalData: {
    userInfo: null,
    urlHome: 'http://127.0.0.1:12323/api',
    token: '',
    plans: [] ,
    baiduToken: "24.7ab7fd6ff787b4be8c7e6e0c19a70fdb.2592000.1676986903.282335-29887558"
  },
})
